#pragma once
#include "HKSDK_2023.h"
#include "DetectPlate.h"
#include "yellow_line_detector.h"
#include "localTcpServer.h"
#include "YOLO.h"
#include "opencv2/opencv.hpp"
#include <thread>
#include <mutex>
#include "CEvtVar.h"

#define ENV_SIDE_NULL (-1)
#define ENV_SIDE_A (0)
#define ENV_SIDE_B (1)

#define CHARGE_LEFT_SIDE  (ENV_SIDE_A)
#define CHARGE_RIGHT_SIDE (ENV_SIDE_B)


#define ENV_CHECK_OK                         (0)
#define ENV_CHECK_COMMU_ERROR                (-1)
#define ENV_CHECK_PEOPLE_ERROR               (-2)
#define ENV_CHECK_LINE_ERROR                 (-3)

struct env_info
{
    int left_plate;			//0：没有，1：有
	int right_plate;		//0：没有，1：有
	int left_line;			//-1:获取图片异常0：没有压线，1：压线
	int right_line;			//-1:获取图片异常0：没有压线，1：压线
	int left_back_line;		//0：没有压线，1：压线	
	int right_back_line;	//0：没有压线，1：压线
	int people;				//0：没有，1：有	
};

class Env_checker
{
public:
    Env_checker();
    ~Env_checker();

	int init();
	HKSDK_2023 hk_sdk;

    int check_info(int nSide);
private:
	void set_info_img_err();
    env_info info={};

    cv::Rect people_left_rect;
    cv::Rect people_right_rect;
	cv::Rect left_rect;
	cv::Rect right_rect;

	std::vector<cv::Point> left_line_pts;
	float left_line_threshold = 0.5;
	
	std::vector<cv::Point> right_line_pts;
	float right_line_threshold = 0.5;

	std::vector<cv::Point> left_back_line_pts;
	float left_back_line_threshold = 0.5;
	
	std::vector<cv::Point> right_back_line_pts;
	float right_back_line_threshold = 0.5;

    YOLO people_detector;
	DetectPlate plate_detector;
	yellow_line_detector line_detector;

	void plate_detect(cv::Mat img);
    void people_detect(cv::Mat img, cv::Rect people_rect);
	void lines_detect(cv::Mat img, int side);
	void line_detect(cv::Mat img, std::vector<cv::Point> pts, float threshold, int& flag);
    int prase_info(int nSide);
};

